<template>
	<view class="pages">
		<u-navbar title="客户参照" :autoBack="true" placeholder bgColor="#fff"></u-navbar>
		<view class="top-search">
			<view class="top-input">
				<u--input
					placeholder="搜索客户名称|编码|电话"
					border="surround"
					shape="circle"
					v-model="searchVal"
					@change="blur"
				></u--input>
			</view>
			<view class="" @click="cleared">
				清空
			</view>
		</view>
		<view class="" v-if="dataList.length != 0">
			<view class="content-list" v-for="(item,index) in dataList" :key="index" @click="toPage(item)">
				<view class="" style="font-size: 34rpx;">{{item[1]}}（{{item[0]}}）</view>
				<view class="phone">
					<view class="">{{item[0]}}</view>
					<view class="">
						<image src="../../static/cell.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getMaterialInformation } from '@/api/index'
	export default {
	  data() {
	    return {
				type: '',
				searchVal: '',
				isMore: true,
				StartRow: 0,
				Limit: 500,
				dataList: [],
				orgInfo: {},
	    }
	  },
	  onLoad(options) {
			if(options.type) {
				this.type = options.type
			}
			this.orgInfo = uni.getStorageSync('orgInfo')
			this.dataList = []
			this.dataInfo()
	  },
	  methods: {
			dataInfo() {
				uni.showLoading({ mask: true });
				// let FilterString = " FName like '%012%' or FNumber like '%012%'  and FDocumentStatus='C'  and FUseOrgId .FNumber='101'"
				let FilterString = "FDocumentStatus ='C' and FForbidStatus='A'"
				if(this.searchVal.trim()!== '') {
					FilterString = " FName like '%"+ this.searchVal +"%' or FNumber like '%"+ this.searchVal +"%' and FDocumentStatus ='C' and FForbidStatus='A'"
				}
				const parameters = [
					{
					    "FormId": "BD_Customer",
					    "FieldKeys": "FNumber,FName",
					    "FilterString": FilterString,
					    "OrderString": "",
					    "TopRowCount": 0,
					    "StartRow": this.Limit * this.StartRow,
					    "Limit": this.Limit,
					    "SubSystemId": ""
					}
				]
				getMaterialInformation({parameters}).then(res => {
					uni.hideLoading();
					if(res.length < this.Limit) {
					  this.isMore = false
					}
					this.dataList = [...this.dataList, ...res]
				})
			},
			cleared() {
				this.searchVal = ''
				this.StartRow = 0
				this.dataList = []
				this.dataInfo()
			},
			blur() {
				this.StartRow = 0
				this.dataList = []
				this.dataInfo()
			},
			toPage(item) {
				if(this.type) {
					if(this.type == '1') {
						let pages = getCurrentPages()
						let prevPage = pages[pages.length - 2]
						prevPage.$vm.orderData.userInfo.name = item[1]
						prevPage.$vm.orderData.userInfo.contact = item[1]
						prevPage.$vm.orderData.userInfo.phone = item[0]
						this.goBack()
					}
					return
				}
				uni.navigateTo({
				  url: '/other/salesOrder/orderDetail?name=' + item[1] + '&phone=' + item[0]
				})
			}
	  },
		onReachBottom() {
		  if(this.isMore) {
		    this.StartRow++
		    this.dataInfo()
		  }
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-input {
		height: 75rpx;
	}
	.pages{
		width: 750rpx;
		min-height: 100vh;
		padding-bottom: 40rpx;
		.top-search {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 30rpx 20rpx;
			margin-top: 20rpx;
			border-bottom: 1px solid #afacac;
			.top-input {
				width: 90%;
				position: relative;
				.btn {
					position: absolute;
					top: 0;
					right: 20rpx;
					height: 75rpx;
					line-height: 75rpx;
					z-index: 99;
				}
			}
		}
		.content-list {
			border-bottom: 1px solid #afacac;
			padding: 15rpx 35rpx;
			.phone {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 20rpx 0;
				image {
					width: 30rpx;
					height: 30rpx;
				}
			}
		}
	}
</style>